# 引入所需库
import cv2 as cv
from PIL import Image
import pytesseract

# 加载图像
image_path = "path_to_your_image.jpg"
img = cv.imread(image_path)

# 转换为灰度图像，便于文字识别
gray_img = cv.cvtColor(img, cv.COLOR_BGR2GRAY)

# 对图像进行二值化处理以增强边缘对比
binary_img = cv.threshold(gray_img, 0, 255, cv.THRESH_BINARY_INV + cv.THRESH_OTSU)[1]

# 使用Tesseract进行OCR识别
text = pytesseract.image_to_string(Image.fromarray(binary_img))

print(f"Recognized text: {text}")